package com.zahb.qadx.util;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by Zdw on 2020/09/29 17:00
 */
public final class RegularUtil {

    // 手机号是否合法
    public static boolean isValidMobileNumber(String mobileNumber) {
        Pattern pattern = Pattern.compile("^[1]\\d{10}");
        Matcher matcher = pattern.matcher(mobileNumber);
        return matcher.matches();
    }

    // 身份证号是否合法
    public static boolean isValidCid(String cid) {
        Pattern pattern_15 = Pattern.compile("^[1-9]\\d{7}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}$");
        Matcher matcher_15 = pattern_15.matcher(cid);
        Pattern pattern_18 = Pattern.compile("^[1-9]\\d{5}[1-9]\\d{3}((0\\d)|(1[0-2]))(([0|1|2]\\d)|3[0-1])\\d{3}([0-9]|X|x)$");
        Matcher matcher_18 = pattern_18.matcher(cid);
        return matcher_15.matches() || matcher_18.matches();
    }

    // 密码是否合法
    public static boolean isValidPassword(String password) {
        Pattern pattern = Pattern.compile("^[A-Za-z0-9]{6,16}$");
        Matcher matcher = pattern.matcher(password);
        return matcher.matches();
    }

    // 短信验证码是否合法
    public static boolean isValidSmsCode(String smsCode) {
        Pattern pattern = Pattern.compile("^\\d{6}$");
        Matcher matcher = pattern.matcher(smsCode);
        return matcher.matches();
    }
}
